const wxCommon = require('./wx_common')
const config = think.config('teddyWx')
module.exports = class extends wxCommon {
  /**
   * 获取会员卡 开发信息
   */
  async getVipComponent (card_id = 'pmSfLvv1lNVdFApob-1XhfHMY5kg', outer_str = 'wxapp') {
    const accessToken = await this.getWxAppAccessToken(config.appId, config.appSecret)
    const url = `https://api.weixin.qq.com/card/membercard/activate/geturl?access_token=${accessToken}`
    const d = await yy.http.post(url, {card_id, outer_str})
    return d
  }

  /**
   * 查看卡券详情
   * @param {*} openid
   * @param {*} card_id
   */
  async getCardInfo (card_id) {
    const accessToken = await this.getWxAppAccessToken(config.appId, config.appSecret)
    const url = `https://api.weixin.qq.com/card/get?access_token=${accessToken}`
    const d = await yy.http.post(url, {card_id})
    return d
  }
  /**
   * 获取用户已领取卡券接口
   * @param {*} openid
   * @param {*} card_id
   */
  async getUserCardList (openid, card_id) {
    const accessToken = await this.getWxAppAccessToken(config.appId, config.appSecret)
    const url = `https://api.weixin.qq.com/card/user/getcardlist?access_token=${accessToken}`
    const d = await yy.http.post(url, {openid, card_id})
    return d
  }
  /**
   *  拉取会员信息（积分查询）接口
   */
  async getUserInfo (code, card_id) {
    const accessToken = await this.getWxAppAccessToken(config.appId, config.appSecret)
    const url = `https://api.weixin.qq.com/card/membercard/userinfo/get?access_token=${accessToken}`
    const d = await yy.http.post(url, {code, card_id})
    return d
  }
}
